package com.iflytek.iot.okhttp.utils;

public class UrlTemplateUtils {

    /**
     * 默认前缀占位符
     */
    public static final String DEFAULT_PLACEHOLDER_PREFIX = "{";

    /**
     * 默认后缀占位符
     */
    public static final String DEFAULT_PLACEHOLDER_SUFFIX = "}";

    /**
     * 占位符前缀
     */
    private static String placeholderPrefix = DEFAULT_PLACEHOLDER_PREFIX;

    /**
     * 占位符后缀
     */
    private static String placeholderSuffix = DEFAULT_PLACEHOLDER_SUFFIX;
    public static  String urlTemplate(String content, Object... values) {
        int start = content.indexOf(placeholderPrefix);
        if (start == -1) {
            return content;
        }
        int valueIndex = 0;
        StringBuilder result = new StringBuilder(content);
        while (start != -1) {
            int end = result.indexOf(placeholderSuffix);
            String replaceContent = String.valueOf(values[valueIndex++]);
            result.replace(start, end + placeholderSuffix.length(), replaceContent);
            start = result.indexOf(placeholderPrefix, start + replaceContent.length());
        }
        return result.toString();
    }
}
